package com.mxf.code.proxy.dynamic_proxy;

import com.mxf.code.proxy.static_proxy.RealSubject;
import com.mxf.code.proxy.static_proxy.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Proxy;

/**
 * Copyright (C), 2017-2022, mxf
 * Author: 28382
 * Date: 2022/10/13 16:22
 * FileName: TestProxyController
 * Description: 代理类测试
 */
@RestController
public class TestDProxyController {


    @GetMapping("/testDProxyControl")
    public void testJDKProxyControl(){
        Subject subject = new RealSubject();
        DynamicProxyHandler proxyHandler = new DynamicProxyHandler(subject);
        Subject o = (Subject) Proxy.newProxyInstance(subject.getClass().getClassLoader(),
                subject.getClass().getInterfaces(),proxyHandler);
        o.doSomething();
    }

    @GetMapping("/testDProxyControl2")
    public void testCJLIBProxyControl2(){
        Subject subject = new RealSubject();
        CglibDynamicProxy cglibDynamicProxy = new CglibDynamicProxy(subject);
        Subject o = (Subject)cglibDynamicProxy.newProxyInstance();
        o.doSomething();
    }
}
